package com.nyist.health.jobs;

/**
 * @description ：
 * @version: 1.0
 */

import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;

import java.io.FileInputStream;
import java.util.UUID;

/**
 * 七牛云工具类
 */
public class QiniuUtils {
    //域名：qdb44kz1s.bkt.clouddn.com
    //应该下发给  客户端的
//    public static String qiniu_img_url_pre = "http://psuyuqoog.bkt.clouddn.com/";
    public static String qiniu_img_url_pre = "http://qdcl5ccdf.bkt.clouddn.com/";
    //    public static String accessKey = "fhuiPBXFTZIgJdtZGuMtCUJ3zSrT7k3AHmVNE4UA";
    public static String accessKey = "zQhsORSPZEjZ6ri0C6PdJCJ8UBUy33KOsopzF7E-";
    //    public static String secretKey = "zKKxCW_HjQmwtl4JI80nMT0Ve2V7VZDbqT4zt_tT";
    public static String secretKey = "cSh_fIf7VAzhkmqs-P7iBSRaHglyYS9VNTQQZ4dT";
    //用户
    public static String bucket = "health-oms";

    /**
     * 删除文件
     *
     * @param fileName 服务端文件名
     */
    public static void deleteFileFromQiniu(String fileName) {
        //构造一个带指定Zone对象的配置类
        Configuration cfg = new Configuration(Zone.zone2());
        String key = fileName;
        Auth auth = Auth.create(accessKey, secretKey);
        BucketManager bucketManager = new BucketManager(auth, cfg);
        try {
            bucketManager.delete(bucket, key);
        } catch (QiniuException ex) {
            //如果遇到异常，说明删除失败
            System.err.println(ex.code());
            System.err.println(ex.response.toString());
        }
    }

}
